@isTest
private class InstrumentProjectBonusControllerTest {
    static testMethod void testMethod1() {



         Product__c p1=TestUtils.createProduct();
        p1.Name='仪器';
        p1.Category0__c = '仪器';
        p1.Model__c='Model1228';
       // p1.ProductStructure__c=ps1.Id;
       // p1.CRMBrand__c = brand.Id;
        p1.RecordTypeId =  Utils.getRecordTypeIdByDevNameAndObjName('NCProduct','Product__c');
        insert p1;

         Account acc=new Account();
        acc.Name='Test1229J';
        acc.Level__c = '一级医院';
        insert acc;
        Dealer__c d = new Dealer__c(
            Only__c='Dealer__c'
        );
        insert d;


        InstallationApply__c IA = new InstallationApply__c();
        //IA.Name='安装申请测试1';
        IA.Instrument__c=p1.Id;

        IA.NEWDealer__c = d.Id;
        IA.Hospital__c = acc.Id;
         IA.InstallEstiDate__c = System.today();
        IA.InstallsNumber__c = 1;
        IA.SupplementOrNot__c = '是';

        insert IA;

          Case cas=new Case();
        cas.AccountId=acc.Id;
        cas.InstallationApply__c = IA.Id ;
        insert cas;

        WorkOrder__c wo = new WorkOrder__c();
        wo.Case__c = cas.Id;
        insert wo;


        Equipment__c e1 = new Equipment__c();
        e1.Account__c = acc.Id;
        e1.IMEINumber__c = '11';
        e1.EndDate__c = System.today();
        e1.Product__c = p1.Id;
        e1.OpponentStatus__c = '正常使用';
        e1.RelatedInstallationApplication__c = IA.Id;
        e1.RelatedWorkOrders__c = wo.Id;
        insert e1;



        InstrumentProjectBonus__c ipb = new InstrumentProjectBonus__c();
        ipb.Manager__c = UserInfo.getUserId();
        ipb.Status__c = '草案中';
        insert ipb;



        InstrumentProjectBonusDetails__c ipbd = new InstrumentProjectBonusDetails__c();
        ipbd.Participants1__c = UserInfo.getUserId();

        ipbd.InstrumentBonus__c= ipb.id;

        ipbd.ApplicationInstrument__c = e1.Id ;

        insert ipbd;

         PageReference page2 = new PageReference('/apex/InstrumentProjectBonus?id='+ipb.Id );
        System.Test.setCurrentPage(page2);
        InstrumentProjectBonusController aic = new InstrumentProjectBonusController();
        aic.init();


        aic.getDetails();

        List<Object> sob = new List<Object>();

        Map<String,String> d1 = new Map<String,String>();
        d1.put('Id', ipbd.Id );
        d1.put('Participants1Rate__c','10');

        sob.add(d1);
        aic.saveJson = EncodingUtil.urlEncode(JSON.serialize(sob ), 'UTF-8');

        aic.save();


        ipb.Status__c = '审批中';

        update ipb; 


    }
}